package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.CityDAO;
import com.xinghou.platform.model.main.City;

@Repository
public class CityDAOImpl  {/*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public City getNameByCode(String code) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT code,pcode,name,Full_name,longitude,latitude,cityID FROM city WHERE code = ?";
		City city = jdbcTemplate.queryForObject(sql, new Object[] { code }, new CityMapper());
		CustomerContextHolder.clearCustomerType();
		return city;
	}
	
	@Override
	public List<City> queryCityListByFullName(String fullName)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		fullName="%"+fullName+"%";
		String sql = "SELECT code,pcode,name,Full_name,longitude,latitude,cityID FROM city WHERE Full_name LIKE ?";
		List<City> list = jdbcTemplate.query(sql, new Object[] { fullName }, new CityMapper());
		CustomerContextHolder.clearCustomerType();
		return list;
	}
	
	public int saveCity(City city)throws DataAccessException {	
		StringBuffer strSQL = new StringBuffer("INSERT INTO city (CODE, pcode, NAME, Full_name, longitude, latitude, cityID)VALUES(?,?,?,?,?,?,?)");		
		Object[] params = {city.getCode(),city.getPcode(),city.getName(),city.getFull_name(),city.getLongitude(),city.getLatitude(),city.getCity_ID()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		jdbcTemplate.savenukey(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return 0;
	}
	
	public List<City> queryCityListByCityid(String cityid)throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT code,pcode,name,Full_name,longitude,latitude,cityID FROM city WHERE cityID = ?";
		List<City> list = jdbcTemplate.query(sql, new Object[] { cityid }, new CityMapper());
		CustomerContextHolder.clearCustomerType();
		return list;
	}
	
	private static final class CityMapper implements RowMapper<City> {
		public City mapRow(ResultSet rs, int rowNum) throws SQLException {
			City city = new City();
			city.setCode(rs.getString("code"));
			city.setPcode(rs.getString("pcode"));
			city.setName(rs.getString("name"));
			city.setLongitude(rs.getDouble("longitude"));
			city.setLatitude(rs.getDouble("latitude"));
			city.setCity_ID(rs.getString("cityID"));
			city.setFull_name(rs.getString("Full_name"));
			return city;
		}
	}

	@Override
	public List<City> queryAllCity() throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT code,pcode,name,Full_name,longitude,latitude,cityID FROM city";
		List<City> list = jdbcTemplate.query(sql, new Object[] { }, new CityMapper());
		CustomerContextHolder.clearCustomerType();
		return list;
	}*/
}
